Repository navigation
fix(web): stop calling revalidatePath during render on first sign-in - #697
Conversation
buildOnboardingSteps({ autoGenerateToken: true }) (rendered inside /lore's
Suspense boundary) called the 'use server' generateToken action, whose
success path calls revalidatePath — Next 15 throws during render for that,
the bare catch{} swallowed it, and the user was left with an orphan
api_tokens row and no token on screen.
Split the mint core (insert + scoping + audit, no revalidate) into a new
server-only lib/token-mint.ts. generateToken (lib/tokens.ts) now wraps it
and revalidates only on success, from the action path. The render path
goes through a new lib/first-token.ts (resolveFirstToken), which calls
mintToken directly and never revalidates — the render already returns the
freshly minted record as initialTokens, so nothing cached is stale.
Adds lorekit.api_token.origin (onboarding|dashboard) to the generate span
so prod can prove the fix. Pins both paths with node-env specs.
|
The dashboard preview for this PR — redeployed on each push that changes the web app.
Preview always points at this PR's latest commit; Deployment is the immutable build of |
|
| Gate | Status | Details |
|---|---|---|
| Description vs. code | How to verify omits onboarding-steps.spec.ts, the new spec that pins the render-path fix. | |
| Prior review feedback | ✅ | Earlier review comments are resolved. |
| Documentation | ✅ | Module headers explain the bug and the fix; key-files.md and otel.md updated. |
| Self-review signals | ✅ | No debug logs, leftover TODOs, or unreviewed stubs. |
| Code review | ✅ | The multi-lens review found no blocking issues. |
Found
Quality — produced 0 → posted inline 0 · cleared 0 · carried forward 0 · deferred 0 · below-bar 0
Optimality — ran — 0 proposals; the server-only mint core is the standard fix for revalidatePath during render
Standards — ran — 2 governing docs scanned, 0 findings
Measurability — ran — web path, no new failure mode in the delta; earlier missing-signal advisories unchanged
Run
full · 86 lines in delta · tier deep · depth checkout
Integrations — not activated (no manifest or lockfile in the diff)
Memories — repo::mthines/lorekit + global — 0 lessons matched; 1 knowledge fact + 1 hotspot re-verified, no relevance rule fired
Nothing to report — severity, 0 files skipped.
pr-reviewer · commit 7834620 · full review · how these findings are produced · updated
…in span attribute The revalidatePath assertions in token-mint.spec could not fail (token-mint never imports next/cache). onboarding-steps.spec now fails if the render goes back to generateToken, and the origin test reads the span attribute. Also correct first-token's comment: expected refusals are not logged.
Why
First sign-in on
/loreminted a token inside a Server Component render by calling the'use server'generate action, whose success path callsrevalidatePath— Next 15 forbids that during render. A barecatch {}swallowed the resulting throw, leaving an orphanapi_tokensrow, no token shown, and a loggedlorekit.api_token.generate.failed.What changed
server-onlymodule,lib/token-mint.ts./lore's render now calls it through a new pure decision module,lib/first-token.ts(resolveFirstToken), which replaces the barecatchwithunstable_rethrow-aware degradation.lib/tokens.ts'sgenerateTokenaction is now a thin wrapper: mint, then revalidate/lore+/settingslayout, on success only — used solely by the dashboard's "Generate token" button.lorekit.api_token.origin(onboarding|dashboard) to the generate span so prod can prove the fix.How to verify
cd packages/web && pnpm exec vitest run --config vitest.config.ts src/lib/onboarding-steps.spec.ts src/lib/first-token.spec.ts src/lib/token-mint.spec.ts src/lib/tokens.spec.tsonboarding-steps.spec.tspins the fix itself: it fails if the/lorerender goes back togenerateToken(mutation-tested).token-mint.spec.tsasserts thelorekit.api_token.originspan attribute.Notes for reviewers
Manual verification against local Supabase (brand-new user, confirm one token + no orphan row) was attempted but local Supabase's DB container would not come up in this sandbox — recorded inconclusive. The unit specs pin the actual mechanism of the bug (no revalidate during the render-path mint).
Out of scope:
/lorein two tabs at once can still get two tokens. That was already possible before this change.No user-facing doc change: internal fix, no behaviour a user configures.